home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Digital Signatures / Digital Signature Demo / Source ƒ / CSignature.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-11  |  6.5 KB  |  216 lines  |  [TEXT/KAHL]

  1. /*
  2.  * CSignature.h
  3.  * Copyright © 1993 Apple Computer Inc.
  4.  * All Rights Reserved
  5.  *
  6.  * This is a Think C class library definition that simplifies
  7.  * access to the AOCE Digital Signature Manager. CSignature
  8.  * is a base class; your applications access it through
  9.  * one of the subclasses: CSignedDataFile to sign or verify
  10.  * a file (as created/used by a CDocument subclass) or
  11.  * CSignedObject to sign or verify an object. 
  12.  * 
  13.  * Errors are returned through the Think Class
  14.  * Library "Failure" routines.
  15.  *
  16.  * If you specify gSIGStatusProc as the status procedure
  17.  * to a sign or verify operation, a default status window
  18.  * will be displayed.
  19.  *
  20.  * Note that there is only one, global, signature context
  21.  * for the entire application. Also note that your
  22.  * application must ensure that the context is deleted
  23.  * before exiting. If you are running under the
  24.  * Think Class Library, the RemovePatches CApplication
  25.  * method must be subclassed to do this (see DemoApp.c).
  26.  * If you have translated this to some other environment,
  27.  * you must patch ExitToShell to remove the context.
  28.  */
  29.  
  30. #define _H_CSignature
  31. /*
  32.  * A.O.C.E. header files.
  33.  */
  34. #include <DigitalSignature.h>
  35. /*
  36.  * TCL header files.
  37.  */
  38. #include <CObject.h>
  39.  
  40. /*
  41.  *** Global values and procedures.
  42.  */
  43. /*
  44.  * gSIGStatusProc is a callback procedure that
  45.  * the Digital Signature Manager calls while
  46.  * signing or verifying data. If you pass
  47.  * this value as the statusProc parameter,
  48.  * a default status window will be shown.
  49.  */
  50. pascal Boolean            gSIGStatusProc(void);
  51.  
  52. /*
  53.  * gSIGContextPtr contains the information the DigitalSignature
  54.  * Manager needs to organize the signature and verification
  55.  * operations.  Note that is an application-wide global. This is
  56.  * so that it is always deleted when the application exits.
  57.  */
  58. extern SIGContextPtr    gSIGContextPtr;
  59. /*
  60.  * DisposeContext disposes of the current signature context
  61.  * (freeing memory and releasing the Digital Signature Manager
  62.  * functions from memory) It does not dispose of the object
  63.  * or any signature. It is called automatically by Dispose,
  64.  * Sign and SignFile, but not by Verify and VerifyFile (as
  65.  * the context is needed by ShowSigner and the other
  66.  * certificate information methods. Calling it when there
  67.  * is no signer context does not cause any errors.
  68.  */
  69. void                    DisposeSignerContext(void);
  70.  
  71. /*
  72.  * The sample application has a STR# resource with three
  73.  * strings that are used by the default status procedure.
  74.  */
  75. enum {
  76.     STRn_SIGStatusProc    = 1024,        /* STR# resource:        */
  77.     kStatusSignString    = 1,        /* "Signing "            */
  78.     kStatusVerifyString,            /* "Verifying "            */
  79.     kStatusDataString                /* "data."                */
  80. };
  81.  
  82. /*
  83.  *** Externally-referenced classes.
  84.  */
  85. class            CDataFile;
  86. class            SIGStatusManager;
  87.  
  88. /*
  89.  *** The CSignature object.
  90.  */
  91. struct CSignature : CObject {
  92. private:
  93.         /*
  94.          * This is the type of the last NewContext request.
  95.          */
  96.         unsigned long                itsContextType;
  97.         /*
  98.          * A window managed by itsStatusManaager is created
  99.          * when you request the default status procedure
  100.          * by passing gSIGStatusProc to Sign or Verify
  101.          */
  102.         SIGStatusManager            *itsStatusManager;
  103. public:
  104.         void                        ISignature(void);
  105.         void                        Dispose(void);
  106.         /*
  107.          * Create a new signature context. This is called
  108.          * by SignPrepare, SignFile, VerifyPrepare, or
  109.          * VerifyFile, or DigestPrepare if it is added.
  110.          * RequestType is one of the following:
  111.          * kSIGSign            Signing
  112.          * kSIGVerify        Verify
  113.          * kSIGDigest        Digest
  114.          */
  115.         void                        NewContext(
  116.             unsigned long                contextType
  117.         );
  118.         /*
  119.          * Fail with an appropriate error (kSIGContextPrepareErr)
  120.          * if there is no context. (The Signature Manager will
  121.          * fail if the context type is incorrect.
  122.          */
  123.         void                        CheckForContext(void);
  124.         /*
  125.          * Return the current context type, or zero
  126.          * if there is no current context. This is needed
  127.          * to enable/disable the ShowSigner menu option,
  128.          * which is valid only after Verify or VerifyFile.
  129.          */
  130.         unsigned long                GetContextType(void);
  131.         /*
  132.          * SignPrepare initializes the signature process.
  133.          * Call it after the data has been created, and
  134.          * you are ready to sign it. The parameters are
  135.          * used as follows:
  136.          *    signerFile        The file specification structure
  137.          *                    for the user's signer file. If
  138.          *                    NULL, the function opens the
  139.          *                    previously-used signer file,
  140.          *                    or displays a Standard File
  141.          *                    dialog box to let the user
  142.          *                    choose a signer file.
  143.          *    prompt            The prompt string displayed
  144.          *                    in the Standard File dialog
  145.          *                    box. Pass "\p" to use the
  146.          *                    default prompt string.
  147.          * Note: if the user cancels the signature
  148.          * request, SignPrepare will fail with error
  149.          * code kSIGUserCanceled. SignPrepare will
  150.          * create a new context if none is established.
  151.          * It returns the size of the signature record.
  152.          */
  153.         Size                        SignPrepare(
  154.             const FSSpec                *signerFile,
  155.             ConstStr255Param            prompt
  156.         );
  157.         /*
  158.          * Show the entire distinguished name of the signer
  159.          * of a block of data. Call only after successfully
  160.          * verifying a signature. prompt is the message
  161.          * you want displayed, if "\p", ShowSigner displays
  162.          * "Verification Successful"
  163.          */
  164.         void                        ShowSigner(
  165.             ConstStr255Param            prompt
  166.         );
  167.         /*
  168.          * Get the signer information for a signature.
  169.          * This is only valid after verification.
  170.          */
  171.         void                        GetSignerInfo(
  172.             SIGSignerInfo                *signerInfo
  173.         );
  174.         /*
  175.          * Get information about a specific certificate.
  176.          * Returns TRUE if successful, FALSE if the
  177.          * certIndex was outside the allowable range.
  178.          * Fails on other errors.
  179.          */
  180.         Boolean                        GetCertInfo(
  181.             unsigned long                certIndex,
  182.             SIGCertInfo                    *certInfo
  183.         );
  184.         /*
  185.          * Get information about a specific attribute of
  186.          * a distinguished name in a specific certificate
  187.          * of a signature.  Returns TRUE if successful,
  188.          * FALSE if the certIndex was outside the allowable
  189.          * range. Fails on other errors
  190.          */
  191.         Boolean                        GetCertNameAttributes(
  192.             unsigned long                certIndex,
  193.             unsigned long                attributeIndex,
  194.             SIGNameAttributesInfo        *attributeInfo
  195.         );
  196. protected:
  197.         /*
  198.          * This method is used to initialize the default
  199.          * status procedure. It is called if the caller
  200.          * specifies gSIGStatusProc in a call to Sign
  201.          * or Verify. Application programs do not call
  202.          * this directly: it is needed only by CSignature,
  203.          * CSignedObject, and CSignedDataFile methods.
  204.          */
  205.         void                        InitDefaultStatusProc(
  206.             ConstStr255Param            actionString,
  207.             ConstStr255Param            objectString
  208.         );
  209.         /*
  210.          * Delete the dialog used by the built-in status
  211.          * procedure. Application programs do not call
  212.          * this directly.
  213.          */
  214.         void                        DisposeDefaultStatusProc(void);
  215. };
  216.